using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Shop : MonoBehaviour
{
    GM gm;

    public Transform gunPlane1;
    public Transform gunPlane2;
    public Transform gunPlane3;
    public Transform gunPlane4;

    public Transform InfoPlane1;
    public Transform InfoPlane2;
    public Transform InfoPlane3;
    public Transform InfoPlane4;

    public Transform yebz;

    private void Start()
    {
        gm = GetComponent<GM>();
        gunPlane1.gameObject.SetActive(Data.gun1);
        gunPlane2.gameObject.SetActive(Data.gun2);
        gunPlane3.gameObject.SetActive(Data.gun3);
        gunPlane4.gameObject.SetActive(Data.gun4);
    }

    public void clickedGun1()
    {
        InfoPlane1.gameObject.SetActive(true);
    }

    public void clickedGun2()
    {
        InfoPlane2.gameObject.SetActive(true);
    }

    public void clickedGun3()
    {
        InfoPlane3.gameObject.SetActive(true);
    }

    public void clickedGun4()
    {
        InfoPlane4.gameObject.SetActive(true);
    }

    public void clickedBuyBtn1()
    {
        if(Data.gold >= 1000)
        {
            Data.gun1 = true;
            gunPlane1.gameObject.SetActive(true);
            Data.gold -= 1000;
            gm.updataGold();
            Data.saveData();
        }
        else
        {
            StartCoroutine(showyebz());
        }
    }

    public void clickedBuyBtn2()
    {
        if (Data.gold >= 5000)
        {
            Data.gun2 = true;
            gunPlane2.gameObject.SetActive(true);
            Data.gold -= 5000;
            gm.updataGold();
            Data.saveData();
        }
        else
        {
            StartCoroutine(showyebz());
        }
    }

    public void clickedBuyBtn3()
    {
        if (Data.gold >= 6000)
        {
            Data.gun3 = true;
            gunPlane3.gameObject.SetActive(true);
            Data.gold -= 6000;
            gm.updataGold();
            Data.saveData();
        }
        else
        {
            StartCoroutine(showyebz());
        }
    }

    public void clickedBuyBtn4()
    {
        if(Data.gold >= 8000)
        {
            Data.gun4 = true;
            gunPlane4.gameObject.SetActive(true);
            Data.gold -= 8000;
            gm.updataGold();
            Data.saveData();
        }
        else
        {
            StartCoroutine(showyebz());
        }
    }

    public void clickedBack()
    {
        InfoPlane1.gameObject.SetActive(false);
        InfoPlane2.gameObject.SetActive(false);
        InfoPlane3.gameObject.SetActive(false);
        InfoPlane4.gameObject.SetActive(false);
    }

    IEnumerator showyebz()
    {
        yebz.gameObject.SetActive(true);
        yield return new WaitForSeconds(2f);
        yebz.gameObject.SetActive(false);
    }
}
